#define _CRT_SECURE_NO_WARNINGS
#include "binaryTree.h"

BT* buynode(int x)
{
	BT* newp = (BT*)malloc(sizeof(BT));
	if (newp == NULL)
	{
		perror("malloc fail");
		return NULL;
	}
	newp->data = x;
	newp->left = NULL;
	newp->right = NULL;
	return newp;
}



void preorder(BT* root)
{
	if (root == NULL)
		return;
	printf("%d ", root->data);
	preorder(root->left);
	preorder(root->right);
}

void Inorder(BT* root)
{
	if (root == NULL)
		return;
	Inorder(root->left);
	printf("%d ", root->data);
	Inorder(root->right);
}

void Postorder(BT* root)
{
	if (root == NULL)
		return;
	Postorder(root->left);
	Postorder(root->right);
	printf("%d ", root->data);
}

int KlevelSize(BT* root,int k)
{
	if (root == NULL)
		return 0;
	if(k == 1)
		return 1;
	else
		return KlevelSize(root->left, k-1)
			+ KlevelSize(root->right, k-1);
}
